#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
verzion=`/usr/bin/sw_vers -productVersion|/usr/bin/sed 's/\.//g'|/usr/bin/cut -c 1,2,3`

#handle the cron entries

#move the cron entries out
/bin/cat /etc/crontab|/usr/bin/sed /start/d|/usr/bin/sed /kicker/d|/usr/bin/sed /proactive/d|/usr/bin/sed /autocron/d > /etc/crontab.tmp

#move the crontab back to where it belongs
/bin/mv /etc/crontab.tmp /etc/crontab


#Stop backgroup processes


#Snow Leopard
if [ $verzion -eq "106" ] ; then
if [ `whoami` = 'root' ]; then
/bin/launchctl unload -w -S Loginwindow /Library/LaunchAgents/com.most.vnc.plist
/bin/launchctl unload -w /Library/LaunchDaemons/com.most.sweeper.plist
fi
fi

#Leopard
if [ $verzion -eq "105" ] ; then
if [ `whoami` = 'root' ]; then
/bin/launchctl unload -w -S Aqua /Library/LaunchAgents/com.most.vnc.plist
/bin/launchctl unload -w /Library/LaunchDaemons/com.most.sweeper.plist
fi
fi

#Tiger

if [ $verzion -eq "104" ] ; then
/bin/launchctl unload -w /Library/LaunchDaemons/com.most.ahm.plist
fi

#Panther

if [ $verzion -lt "104" ]; then
/sbin/systemstarter stop mhmd 
fi

#MHM Desktop and MHMQC

/usr/bin/killall MHMQC
/usr/bin/killall MHMDesktop


#remove files and folders

/bin/rm -rf /Library/StartupItems/mhmd/
/bin/rm /Library/LaunchDaemons/com.most.ahm.plist
/bin/rm /Library/LaunchDaemons/com.most.sweeper.plist
/bin/rm /Library/LaunchAgents/com.most.vnc.plist
/bin/rm /Library/Preferences/AutoHelpMate.plist
/bin/rm -rf /etc/auto/
/bin/rm -rf /etc/proactive/
/bin/rm /etc/autocron.sh


if [ $verzion -lt "104" ]; then


#move the hostconfig entries out

/bin/cat /etc/hostconfig|/usr/bin/sed /MHMD/d > /etc/hostconfig.tmp

#move the hostconfig back to where it belongs

/bin/mv /etc/hostconfig.tmp /etc/hostconfig

fi

#add necessary plist entries

updatestamp=`/bin/date +%s`

/usr/bin/defaults write /Library/Preferences/AutoHelpMate checkInStamp -int $updatestamp
#/usr/bin/defaults write /Library/Preferences/AutoHelpMate AHMClass -int 1

#Leopard
if [ $verzion -eq "105" ] ; then
if [ `whoami` = 'root' ]; then
/bin/launchctl unload -S Aqua /Library/LaunchAgents/com.most.vnc.plist
/bin/launchctl unload -w Aqua /Library/LaunchAgents/com.most.vnc.plist

fi
fi


#Tiger

if [ $verzion -eq "104" ] ; then
/bin/launchctl unload -w /Library/LaunchDaemons/com.most.ahm.plist
fi

#Panther

if [ $verzion -lt "104" ]; then
/sbin/systemstarter stop mhmd 
fi

exit 0